package com.example.smartagrisys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartagrisys.entity.OrderItem;
import com.example.smartagrisys.mapper.OrderItemMapper;
import com.example.smartagrisys.service.OrderItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 订单项服务实现类
 */
@Slf4j
@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements OrderItemService {

    @Override
    public Integer getProductSalesCount(Long productId) {
        try {
            return baseMapper.selectSumQuantity(productId);
        } catch (Exception e) {
            // 记录错误但返回0，避免系统崩溃
            log.error("获取产品销量失败：" + e.getMessage(), e);
            return 0;
        }
    }
} 